package com.example.demo.mapper;

import com.example.demo.entity.Instorage;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface InstorageMapper {
    // 添加入库记录
    @Insert("INSERT INTO instorage(iid, itime, icarnum, iweight, iquantity, isbelong, irweight) " +
            "VALUES(#{iid}, #{itime}, #{icarnum}, #{iweight}, #{iquantity}, #{isbelong}, #{irweight})")
    int createInstorage(Instorage instorage);

    // 删除入库记录
    @Delete("DELETE FROM instorage WHERE iid = #{iid}")
    int deleteInstorage(Integer iid);

    // 根据ID查询入库记录
    @Select("SELECT * FROM instorage WHERE iid = #{iid}")
    Instorage findInstorageById(Integer iid);

    // 查询所有入库记录
    @Select("SELECT * FROM instorage")
    List<Instorage> findAllInstorages();

    // 根据仓库ID查询入库记录
    @Select("SELECT * FROM instorage WHERE isbelong = #{sid} ORDER BY iid")
    List<Instorage> findInstoragesByStorageId(Integer sid);

    // 查询真实吨数
    @Select("SELECT irweight FROM instorage WHERE iid = #{iid}")
    double findRealWeight(Integer iid);

    // 更新真实吨数
    @Update("UPDATE instorage SET irweight = #{irweight} WHERE iid = #{iid}")
    int updateRealWeight(@Param("iid") Integer iid, @Param("irweight") double irweight);
}